home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEX-UTIL / DVIPS_55 / dvips / src / c / scalewidth < prev    next >
Text File  |  1994-05-06  |  901b  |  29 lines

  1. /*
  2.  *   Code to scale dimensions.  Takes two thirty-two bit integers, multiplies
  3.  *   them, divides them by 2^20, and returns the thirty-two bit result.
  4.  *   The first integer, the width in FIXes, can lie between -2^24 and 2^24-1.
  5.  *   The second integer, the scale factor, can lie between 0 and 2^27-1.  The
  6.  *   arithmetic must be exact.  The answer is truncated to an integer.
  7.  *
  8.  *   Since this math is special, we put it in its own file.  It is the only
  9.  *   place in the program where such accuracy is required.
  10.  */
  11. #include "dvips.h" /* The copyright notice in that file is included too! */
  12.  
  13. integer
  14. scalewidth(a, b)
  15.         register integer a, b ;
  16. {
  17.   register integer al, bl ;
  18.  
  19.   if (a < 0)
  20.      return -scalewidth(-a, b) ;
  21.   if (b < 0)
  22.      return -scalewidth(a, -b) ;
  23.   al = a & 32767 ;
  24.   bl = b & 32767 ;
  25.   a >>= 15 ;
  26.   b >>= 15 ;
  27.   return ( ((al*bl/32768) + a*bl+al*b)/32 + a*b*1024) ;
  28. }
  29.